import com.mng.annoTest.Springconfig;
import com.mng.annoTest.Uservice;
import com.mng.beanTest1.User;
import com.mng.beanTest2.Emp;
import com.mng.beanTest3.ColleationTry;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class main {
    //一般属性注入
    @Test
    public void test1(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean1.xml");
        User user1 = applicationContext.getBean("user4", User.class);
        User user2 = applicationContext.getBean("user4", User.class);
        System.out.println(user1);
        System.out.println(user2);
    }
    //对象属性注入
    @Test
    public void test2(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean2.xml");
        Emp emp1 = applicationContext.getBean("emp2", Emp.class);
        System.out.println(emp1);

    }
    //集合属性注入
    @Test
    public  void  test3(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean3.xml");
        ColleationTry colleationTry1 = applicationContext.getBean("colleationTry2", ColleationTry.class);
        System.out.println(colleationTry1);

    }
    //beanFactory测试
    @Test
    public void test4(){
        ApplicationContext context = new ClassPathXmlApplicationContext("FactoryBeanTest.xml");
        Emp emp = context.getBean("empFactory1", Emp.class);
        System.out.println(emp);
    }


    //Autowired test
    @Test
    public void test5(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean2.xml");
        Emp emp = applicationContext.getBean("emp3", Emp.class);
        System.out.println(emp);

    }
    //anno test
    @Test
    public  void test6(){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Springconfig.class);
        Uservice uservice = applicationContext.getBean("uservice", Uservice.class);
        uservice.test();
    }

}
